

let updateAddAddressForm = new Vue({
    el:'#updateAddressForm',
    data:{
        provinceVo:{},
        provinceActive:"1",
        cityVo:{},
        cityActive:"1",
        zoneVo:{},
        provinceNames:[],
        cityNames:[],
        zoneNames:[],
        province: '',
        cityName:'',
        zoneName:'',
        street:'',
        postcode:'',
        customerName: '',
        phone:'',
        status:'',
        hasError: false
    },
    methods:{
        updateAddressFormTwo:function () {
            let address = {};
            console.log('Submit');
             address.province=$("#updateAddressForm select[name='provinceName'] option:checked").val();
             address.cityName=$("#updateAddressForm select[name='cityName'] option:checked").val();
             address.zoneName=$("#updateAddressForm select[name='zoneName'] option:checked").val();
             address.street=$("#updateAddressForm textarea").val();
             address.postcode=$("#updateAddressForm input[name='postcode']").val();
             address.customerName=$("#updateAddressForm input[name='customerName']").val();
             address.phone=$("#updateAddressForm input[name='phone']").val();
             address.status=$("#updateAddressForm input[name='status']").val();
             address.id=$("#updateAddressForm input[name='id']").val()
            let form = new FormData();
            form.append("provinceName",address.province);
            form.append("cityName",address.cityName);
            form.append("zoneName",address.zoneName);
            form.append("street",address.street);
            form.append("postcode",address.postcode);
            form.append("customerName",address.customerName);
            form.append("phone",address.phone);
            form.append("status",address.status);
            form.append("id",address.id);
            console.log(address);
            axios({
                method:'post',
                url:"/updateAddress",
                data:form
            })
                .then(function(r) {
                    console.log("|"+r.status+"|"+OK+"|");
                    console.log(r);
                    if(r.data=="yes"){
                        console.log("地址修改成功");
                        console.log(r.data);
                        updateAddAddressForm.hasError = false;
                        location.href = '/address.html';
                    }else{
                        console.log(r.data);
                        updateAddAddressForm.hasError = true;
                        updateAddAddressForm.message = r.data;
                    }
                });
        },
        getProvinceNames:function () {
            axios({
                url:"/portal/province",
                method:"get"
            }).then(function (response) {
                updateAddAddressForm.provinceVo=response.data;

            })
        },
        // getProvinceNamesById:function(id){
        //     axios({
        //         url:"/portal/"+id+"/province",
        //         method:"get"
        //     }).then(function (response) {
        //         updateAddAddressForm.provinceVo=response.data;
        //     })
        // },
        getCityNames:function (event) {
            // let index=obj.selectedIndex;
            this.provinceActive=event.target.value;
            console.log(provinceActive)
            axios({
                url:"/portal/"+this.provinceActive+"/city",
                method: "get"
            }).then(function (response) {
                updateAddAddressForm.cityVo=response.data;
            })
            this.$options.methods.getProvinceNames();
        },
        getZoneNames:function (event) {
            this.cityActive=event.target.value;
            axios({
                url:"/portal/"+this.cityActive+"/zone",
                method:"get"
            }).then(function (response) {
                updateAddAddressForm.zoneVo=response.data;
            })
        },

    },
    created:function () {
        this.getProvinceNames();
    }
});